home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n05.arc / ANSIHERE.ASM next >
Assembly Source File  |  1990-02-13  |  4KB  |  86 lines

  1. ;      ANSIHERE.ASM - Check to see if ANSI.SYS is loaded and display message.
  2. ;                     Exit with errorlevel = 1 if ANSI is loaded, 0 otherwise.
  3. ;                     By William Loud
  4. ;
  5. ;      SYNTAX:  ANSIHERE [S]
  6. ;          The 'S' parameter will suppress output of the status
  7. ;          message when ANSIHERE is used in batch files.
  8. ;
  9. ;   This program checks for ANSI by writing the ANSI Device Status Report
  10. ;   (DSR) sequence to the display.  If ANSI is loaded, it will output a
  11. ;   Cursor Position Report (CPR) to the standard input device (the keyboard).
  12. ;   Therefore, if you issue a DSR and find anything in the keyboard buffer,
  13. ;   you can assume it's a CPR and that ANSI is loaded.  Conversely, if the
  14. ;   keyboard buffer is empty, then ANSI is not loaded.
  15.  
  16.               TITLE     ANSIHERE
  17.  
  18. CODE_SEG      SEGMENT                        ;Define code segment
  19.               ASSUME    cs:CODE_SEG,ds:CODE_SEG
  20.               ORG       100h
  21.  
  22. start:        jmp       begin                ;skip over data
  23.  
  24. Identify      DB        ' ANSIHERE.COM  ',26
  25. Errorlevel    DB        0             ;exit code, default is no ANSI
  26. DSR_string    DB        27,'[6n$'     ;Device Status Report ANSI string
  27. YesMsg        DB        'ANSI.SYS is loaded.$'
  28. NoMsg         DB        13,'ANSI.SYS is NOT loaded.$'
  29. EraseDSR      DB        13,32,32,32,32,'$'
  30. ; The carriage return at the beginning of EraseDSR returns the cursor
  31. ; to the start of the current line and the four spaces will overwrite
  32. ; the garbage left by the DSR_string if ANSI is not loaded.
  33.  
  34. begin:        mov       dx,OFFSET DSR_string  ;display the ANSI DSR_string
  35.               call      Print_String          ; to see if ANSI is loaded
  36.  
  37.               mov       ah,0Bh             ;check for key in the keyboard
  38.               int       21h                ; buffer - if there's anything
  39.               cmp       al,0FFh            ; there, ANSI is loaded
  40.               je        clear_key          ;go empty the buffer
  41.  
  42. ; Keyboard buffer is empty so ANSI is not loaded.
  43.               mov       dx,OFFSET EraseDSR ;erase the garbage left by the
  44.               call      Print_String       ; DSR_String
  45.               mov       dx,OFFSET NoMsg    ;point to 'not loaded' message
  46.               jmp       parse              ; and check command line arguments
  47.  
  48. ; ANSI is loaded.  We must empty the keyboard buffer because it contains
  49. ; a Cursor Position Report which DOS will attempt to execute when this
  50. ; program terminates.
  51. clear_key:    mov       ah,06h             ;get key from the keyboard buffer
  52.               mov       dl,0FFh            ; don't wait if the buffer is empty
  53.               int       21h                ; and don't print it to the screen
  54.               jnz       clear_key          ;go back for more until buffer is
  55.                                            ; empty and zero flag is set
  56.  
  57.               mov       dx,OFFSET YesMsg   ;point to 'ANSI is loaded' message
  58.               mov       Errorlevel,01h     ;set errorlevel = 1
  59.  
  60. ; Check for command line arguments.  If 'S' was entered on the command line
  61. ; we won't display the status message.  When ANSIHERE is used in batch files
  62. ; we'll want to suppress the status message and use errorlevel tests to
  63. ; control program flow.
  64.  
  65. parse:        mov       bx,0080h           ;point to command line in PSP
  66. parse_loop:   inc       bx                 ;point to next character
  67.               cmp       Byte Ptr [bx],13   ;is it a carriage return?
  68.               je        printMsg           ;done - print status message
  69.               and       Byte Ptr [bx],5Fh  ;convert to uppercase
  70.               cmp       Byte Ptr [bx],'S'  ;is it 'S' ?
  71.               jnz       parse_loop         ;no - get another character
  72.               jmp       exit               ;yes - skip status message
  73.  
  74. printMsg:     call      Print_String       ;print status message
  75. exit:         mov       ah,4Ch             ;DOS exit function in ah
  76.               mov       al,Errorlevel      ; errorlevel in al
  77.               int       21h
  78.  
  79. ;--------------------- Print_String subroutine -----------------------------
  80. Print_String: mov       ah,09h            ;print string function
  81.               int       21h
  82.               ret
  83.  
  84. CODE_SEG      ENDS
  85.               END       start
  86.